package library.gui.component;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;

public class InputLine extends BorderPane implements TextLine {

	private Label label;
	private TextField textField;

	public InputLine(String key, boolean sec) {
		
		this.setPrefHeight(20);
		
		this.label = new Label(key);
		this.label.setAlignment(Pos.CENTER_LEFT);
		this.label.setPadding(new Insets(0, 10, 0, 0));
		this.label.prefHeightProperty().bind(this.heightProperty());
		this.textField = sec ? new PasswordField() : new TextField();
		
//		this.textField.setPadding(new Insets(0, 10, 0, 10));
		this.textField.prefHeightProperty().bind(this.heightProperty());
		this.textField.prefWidthProperty().bind(this.widthProperty());
		
		this.setLeft(label);
		this.setCenter(textField);
		
	}
	
	public void scale(double left) {
		label.prefWidthProperty().bind(this.widthProperty().multiply(left));
		textField.prefWidthProperty().bind(this.widthProperty().multiply(1-left));
	}
	
	public void setValue(String string) {
		this.textField.setText(string);
	}
	
	public void clear() {
		setValue("");
	}
	
	public String getValue() {
		return textField.getText();
	}
	
}
